﻿@model SelfMadeMillionaire.Web.Infrastructure.ViewModels.MailingList.MailingListViewModel
@{
	ViewBag.Title = "User Management";
	Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}


@using (Html.BeginForm("Index", "MailingList", FormMethod.Get, new { @class = "form-horizontal" }))
{	
	<fieldset class="border1">
		<legend class="border1">Search</legend>
		<div class="row">
            @Html.HiddenFor(m => m.SortOrder)
			<div class="col-sm-6">
				<div class="form-group">
					@Html.LabelFor(m => m.FirstName, new { @class = "col-sm-4 control-label" })
					<div class="col-sm-8">
						@Html.TextBoxFor(m => m.FirstName, new { @class = "form-control" })
						@Html.ValidationMessageFor(m=>m.FirstName)
					</div>
				</div>
			</div>
			<div class="col-sm-6">
				<div class="form-group">
					@Html.LabelFor(m => m.SelectedProduct, new { @class = "col-sm-4 control-label" })
					<div class="col-sm-8">
						@Html.DropDownListFor(m => m.SelectedProduct, Model.ProductTypes, new { @class = "form-control" })
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					@Html.LabelFor(m => m.LastName, new { @class = "col-sm-4 control-label" })
					<div class="col-sm-8">
						@Html.TextBoxFor(m => m.LastName, new { @class = "form-control" })
						@Html.ValidationMessageFor(m=>m.LastName)
					</div>
				</div>
			</div>
			<div class="col-sm-6">
				<div class="form-group">
					@Html.LabelFor(m => m.Email, new { @class = "col-sm-4 control-label" })
					<div class="col-sm-8">
						@Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
						@Html.ValidationMessageFor(m=>m.Email)
					</div>
				</div>
			</div>			
		</div>
		<div class="row">
			<div class="col-sm-12">
				<div class="pull-right">
					<button type="submit" id="find-mailing-list" class="btn btn-default">Find</button>
				</div>
			</div>
		</div>
	</fieldset>
}

<div class="table_container">
	<div id="mailing-list">
		@Html.Partial("MailingListTable")
	</div>
	<button class="btn btn-default" id="btnAddNew">Add New</button>
</div>

<div id="edit-modal-container" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="edit-dialog-label" aria-hidden="true">
	@Html.Partial("Edit", Model.EditModel)
</div>

<div class="modal fade" id="success-dialog" tabindex="-1" role="dialog" aria-labelledby="add-dialog-label" aria-hidden="true">
    <div class="modal-dialog">
	    <div class="modal-content">

            <div class="modal-header">
			    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="success-dialog-label"></h4>
			</div>
			<div class="modal-body">
			    <span id="msgText"/>
			</div>
			<div class="modal-footer">
			    <div class="row">
                    <div class="col-sm-12">
					    <div class="pull-right">
                            <a href="#" class="btn btn-default width80" data-dismiss="modal">OK</a>
						</div>
					</div>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
</div>

<script type="text/javascript">
	$(function () {

		$("#find-mailing-list").click(function (e) {
			e.preventDefault();

			if($(this).closest("form").valid())
				refresh();
		});
		
	});

	function refresh() {
		$.ajax({
			url: "@Url.Action("Index")",
			data: {
				firstName: $("#@Html.IdFor(m => m.FirstName)").val(),
				lastName: $("#@Html.IdFor(m => m.LastName)").val(),
				selectedProduct: $("#@Html.IdFor(m => m.SelectedProduct)").val(),
			    email: $("#@Html.IdFor(m => m.Email)").val(),
			    sort: $("#@Html.IdFor(m => m.SortOrder)").val(),
			    page: '@(Model.Page.ToString())'
			},
			cache: false,
			success: function (result) {
				$("#mailing-list").html(result);
			}
		});
	}

    function ShowModalMessage(m) {
        $("#msgText").text(m);
        $("#success-dialog").modal();
    }

</script>


